

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public class Indirizzi {

	private ArrayList<String> indirizzi = null;

	public Indirizzi(String p) {

		indirizzi = new ArrayList<String>();

		try {
			
			FileReader fr = new FileReader(p);
			BufferedReader br = new BufferedReader(fr);
			String q;
			
			while ((q=br.readLine())!= null) {
				
				indirizzi.add(q);
			}
			
			br.close();
			fr.close();
			
		} 
		catch (FileNotFoundException e) {
			
			System.err.println("File non trovato");
			e.printStackTrace();
			
		} 
		catch (IOException e) {
			
			System.err.println("Erroe generico I/O");
			e.printStackTrace();
			
		}

		for (int m=0; m<indirizzi.size();m++) {
			System.out.println(m + "\t" + indirizzi.get(m));
		}
	}

	public synchronized String getIndirizzo() {
		
		String s;
		
		try{
		
			s = indirizzi.get(0);
			indirizzi.remove(0);
		
		}
		catch(IndexOutOfBoundsException e){
			
			s = null;
			
		}
		
		return s;
		
	} 

}
